/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package component;

import com.dhchoi.CountdownTimer;
import controlP5.ControlP5;
import controlP5.Textlabel;
import ddf.minim.AudioMetaData;
import ddf.minim.AudioPlayer;
import processing.core.PApplet;

/**
 *
 * @author Caliste
 */
public class SoundTimer
{
    private long _length;
    private int _second;
    private int minute;
    private int _hour;
    private boolean _running;
    private int _startTime;
    private int _stopTime;
    private CountdownTimer _timer;
    private Textlabel _tlTimer;
    private String _timerCallbackInfo;
    private AudioPlayer _player;
    
    public SoundTimer(PApplet mainApp, AudioPlayer player, Textlabel tl)
    {
        ControlP5 controlP5 = new ControlP5(mainApp);
        _tlTimer = tl;
        _player = player;
        init();
        
        _timer = CountdownTimer.getNewCountdownTimer(mainApp).configure(100, _length);
        
        /*_tlTimer = controlP5.addTextlabel("lbFileSelected");
        _tlTimer.setSize(100, 80);
        _tlTimer.setPosition(100, 430);
        _tlTimer.setValue("Valeur");*/
    }
    
    private void init()
    {
        AudioMetaData meta = _player.getMetaData();
        _length = meta.length();
    }
    
    public void start()
    {
        _timer.start();
        _running = true;
    }
    
    public void stop()
    {
        _timer.stop();
        _running = false;
    }

    /**
     * @return the _tlSoundTimer
     */
    public Textlabel getTlTimer() {
        return _tlTimer;
    }
    
    /**
     * Cette methode permet de mettre
     * a jour la valeur du TextLabel.
     * @param value
     */
    public void setValueTlTimer(String value) 
    {
        _tlTimer.setValue(value);
    }
    
    /**
     * Cette methode permet
     * d'initialiser l'object courant
     * apres que l'utilisateur ait
     * cliquer sur le bouton "stop";
     */
    public void clearValueTlTimer()
    {
        init();
        _tlTimer.setValue("");
    }
    
    /**
     * @return the _length
     */
    public long getLength() {
        return _length;
    }
}
